package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.service.ApartmentInfoService;
import com.atguigu.lease.model.service.LeaseTermService;
import com.atguigu.lease.model.service.RoomInfoService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 老韦
* @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
* @createDate 2024-08-16 18:28:23
*/
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
    implements LeaseAgreementService{


    @Autowired
    LeaseAgreementMapper leaseAgreementMapper;

    @Autowired
    ApartmentInfoService apartmentInfoService;

    @Autowired
    RoomInfoService roomInfoService;

    @Autowired
    PaymentTypeServiceImpl paymentTypeService;

    @Autowired
    LeaseTermService leaseTermService;

    @Override
    public IPage<AgreementVo> listPageAgreementVo(IPage<AgreementVo> page, AgreementQueryVo queryVo) {

        return leaseAgreementMapper.listPageAgreementVo(page, queryVo);
    }



    @Override
    public AgreementVo getAgreementVoById(Long id) {

        //根据id查询租约信息
        AgreementVo agreementVo = new AgreementVo();

        //查询基本的租约信息
        LeaseAgreement byId = super.getById(id);

        //将基本的转换到Vo的
        BeanUtils.copyProperties(byId,agreementVo);


        //根据租约信息种的apartment_id查询签约公寓
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(agreementVo.getApartmentId());
        agreementVo.setApartmentInfo(apartmentInfo);

        //根据租约信息种的房间id查询签约的房间信息
        RoomInfo roomInfo = roomInfoService.getById(agreementVo.getRoomId());
        agreementVo.setRoomInfo(roomInfo);

        //根据租约信息种的支付方式的id 查询支付方式
        PaymentType paymentType = paymentTypeService.getById(agreementVo.getPaymentTypeId());
        agreementVo.setPaymentType(paymentType);


        //根据租期ID查租期
        LeaseTerm leaseTerm = leaseTermService.getById(agreementVo.getLeaseTermId());
        agreementVo.setLeaseTerm(leaseTerm);

        return agreementVo;
    }


}




